//
// Copyright (c) 2009 All Right Reserved
//
// vl
//
// 2018-12-01
// Contains ...
using System;
using System.Windows;
using System.Windows.Media;
namespace LargoPanels.Editor
{
/// A base chart master.
public partial class LineSpace : FrameworkElement
{
#region Public properties - DrawingVisual
///
/// Gets or sets the drawing visual.
///
///
/// The drawing visual.
///
public DrawingVisual DrawingVisual { get; set; }
///
/// Gets the number of visual child elements within this element. Mandatory overrides for VisualChildrenCount property.
///
protected override int VisualChildrenCount => 1;
///
/// Overrides , and returns a child at the specified index from a collection of child elements.
///
/// The zero-based index of the requested child element in the collection.
///
/// The requested child element. This should not return null; if the provided index is out of range, an exception is thrown.
///
/// Argument Out Of Range Exception
protected override Visual GetVisualChild(int index) {
if (index != 0) {
throw new ArgumentOutOfRangeException();
}
return this.children[index];
}
#endregion
///
/// When overridden in a derived class, participates in rendering operations that are directed by the layout system. The rendering instructions for this element are not used directly when this method is invoked, and are instead preserved for later asynchronous use by layout and drawing.
///
/// The drawing instructions for a specific element. This context is provided to the layout system.
protected override void OnRender(DrawingContext drawingContext) {
/* using (DrawingContext dc = this.EditorSpace.DrawingVisual.RenderOpen()) {
drawingContext.DrawRectangle(Brushes.Blue, new Pen(Brushes.Yellow, 3), new Rect(new Point(100, 100), new Point(400, 200)));
}; */
//// Set coordinates and sizes of cells + shifts according to scrollbars
this.PlaceCells();
//// Draw visible area
this.DrawCells(drawingContext);
}
///
/// Creates the drawing visual.
///
/// Returns value.
private DrawingVisual CreateDrawingVisual() { //// int stationObjectSize, double actualWidth, double actualHeight) {
//// initialize canvasGrid
this.DrawingVisual = new DrawingVisual();
//// end using clause
return this.DrawingVisual;
}
#region Private methods - Draw cells on Canvas
///
/// Places the cells.
///
private void PlaceCells() {
foreach (var cell in this.VoiceCells) {
cell.Left = this.LeftSpace;
cell.Top = this.TopSpace + this.TopMargin /*- this.TopScroll */ + (cell.LineIndex * SeedSize.CurrentHeight);
}
}
///
/// Draws the cells.
///
/// The drawing context.
private void DrawCells(DrawingContext drawingContext) {
foreach (var cell in this.VoiceCells) {
if (cell.Top + cell.Height < this.TopSpace + this.TopMargin || cell.Top > 700) {
continue;
}
cell.DrawCell(drawingContext, true);
}
}
#endregion
}
}